package com.shj.controller;

import com.shj.entity.SysPerson;
import com.shj.service.SysPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/biz/person")
public class SysPersonController {
    @Autowired
    private SysPersonService sysPersonService;

    @RequestMapping("/list")
    public String findAll(Model model, String personName) {
        if (personName == null || "".equals(personName)) {
            personName = null;
        }
        List<SysPerson> list = sysPersonService.findAll(personName);
        model.addAttribute("list", list);
        return "person/person_list";
    }

    @RequestMapping("/openEdit")
    public String openEdit(Model model, String perCode) {
        SysPerson sysPerson = sysPersonService.findByPerNo(perCode);
        model.addAttribute("person", sysPerson);
        return "person/person_edit";
    }

    @RequestMapping("/edit")
    public String edit(Model model, SysPerson sysPerson) {
        sysPersonService.edit(sysPerson);
        return findAll(model, null);
    }

    @RequestMapping("/delete")
    public String delete(Model model, String perCode) {
        sysPersonService.delete(perCode);
        return findAll(model, null);
    }

}
